using System;

using System.Xml;
using System.Xml.Xsl;
using System.Net.Mail;

/*	-----------------------------------------------------------------------	
	Copyright:	umlungu consulting (pty) ltd
	Author:		Alan Benington	
	Started:	2006-03-08	
	Status:		release	
	Version:	2.0.0
	Buidl:		20070524
	License:	GNU General Public License
	-----------------------------------------------------------------------	*/

/*	-----------------------------------------------------------------------	
	Development Notes:
	==================
	20070524:	Modification for .Net 2.0
	20070703:	Removed net_2_0 directive (from compatibility build)
	-----------------------------------------------------------------------	*/

namespace umlungu.engineX.blogX {
	/// <summary>
	/// umlungu engineX blog page class.
	/// </summary>
	public class contactX : uiX {
		#region Invisible properties
		private string _contactauthor, _contactemail, _contacttext;
		#endregion

		#region Visible properties
		#endregion

		#region Constructors/Destructors
		/// <summary>Constructor</summary>
		public contactX() : base("contactX") {
		}
		#endregion

		#region Protected methods
		/// <summary>
		/// Gets contact information and sends the contact email
		/// </summary>
		protected override void _LoadAdditional() {
			loadContact();
			sendContact();
		}
		#endregion

		#region Private methods
		private void sendContact() {
			string username = (Author != null && Author != "")? Author : Blogspace.GetAttribute("admin");
			x_user userx = new x_user(Application);
			userx.Get(username);
			string message = String.Concat("Name: ", _contactauthor, "\nEmail: ", _contactemail, "\nText: ", _contacttext);
			Debugger.Spoor("sendContact", "Message:(to:", userx.Email, ")\n", message);
			try {
				SmtpClient smtp = new SmtpClient();
				//smtp.Host = "localhost";	// for whatever reason doesnt work on umlungu server
				smtp.Send("Thoughtspace", userx.Email, "Thoughtspace Contact", message);
			}
			catch(System.Exception e) {
				Response.Write(String.Concat("\n<!-- Could not send email: '", e.Message, "' -->\n"));
			}
		}
		private void loadContact() {
			_contactauthor = (Request.Form["Contact_name"] == null)? "[unknown author]": Request.Form["Contact_name"];
			_contactemail = (Request.Form["Contact_email"] == null)? "[no email address]": Request.Form["Contact_email"];
			_contacttext = (Request.Form["Contact_message"] == null)? "[no message]": Request.Form["Contact_message"];
		}
		#endregion
	}
}
